#include "levelup.h"
#include "ui_levelup.h"
#include "turret.h"
#include "game.h"
#include <QPropertyAnimation>
Levelup::Levelup(Game *parent) :
    QWidget(parent),fath(parent),
    ui(new Ui::Levelup)
{
    ui->setupUi(this);
    this->setWindowFlags(Qt::FramelessWindowHint);
    this->setAttribute(Qt::WA_TranslucentBackground);
    setAttribute(Qt::WA_DeleteOnClose);
    this->setVisible(false);
}

Levelup::~Levelup()
{
    delete ui;
}

void Levelup::play(Turret *turret)
{
    m_turret=turret;
    this->setGeometry(turret->getPos().x()-190/2,turret->getPos().y()-190/2,190,190);
    this->show();

    //动画
    QToolButton *tool[5];
    tool[0]=ui->Button;
    tool[1]=ui->Button_2;
    tool[2]=ui->Button_3;
    tool[3]=ui->Button_4;
    tool[4]=ui->Button_5;
    for(int i=0;i<5;i++)
    {
    QPropertyAnimation *animation = new QPropertyAnimation(tool[i], "geometry");
    animation->setDuration(500);
    animation->setStartValue(QRect(68,75,50,50));
    animation->setEndValue(tool[i]->geometry());
    animation->setEasingCurve(QEasingCurve::OutCubic);
    animation->start();
    }
}

void Levelup::notplay()
{
    this->hide();
}
void Levelup::mousePressEvent(QMouseEvent *event)
 {
     fath->leveling=false;
     notplay();
 }

void Levelup::on_Button_clicked()
{
    if(m_turret->levelup(0)){
        fath->leveling=false;
        notplay();
        }

}

void Levelup::on_Button_2_clicked()
{
    if(m_turret->levelup(1)){
        fath->leveling=false;
        notplay();
        }
}

void Levelup::on_Button_3_clicked()
{
    if(m_turret->levelup(2)){
        fath->leveling=false;
        notplay();
        }
}

void Levelup::on_Button_4_clicked()
{
    if(m_turret->levelup(3)){
        fath->leveling=false;
        notplay();
        }
}

void Levelup::on_Button_5_clicked()
{
    fath->remove_turret(m_turret);
    fath->leveling=false;
    notplay();
}
